<template>
	<view class="content">
		<!-- 头部 -->
		<view class="header">
			<view>
			   <view class="headerimg"><img :src="currentUser.img" alt="" ></view>
			   <view>手机号码:{{currentUser.phone}}</view>
			   <view>ID:{{currentUser.id || '123456'}}</view>
			</view>
		</view>
		<!-- 中间 -->
		<view class="middle">
			<view class="middlelist">
				<view class="middleitem" @click="myaddress">
					<view ><img src="/static/imgs/addressme.png" alt="" height="30px"></view>
					我的地址
				</view>
				<view class="middleitem" @click="mylove">
					<view><img src="/static/imgs/loveme.png" alt="" height="30px"></view>
					我的关注
				</view>
				<view class="middleitem" @click="myorders">
					<view><img src="/static/imgs/cartme.png" alt="" height="30px"></view>
					我的订单
				</view>
			</view>
		
		</view>
		<!-- 底部 -->
		<view class="middlelogin">
			<button type="primary" @click="logout">退出登录</button>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentUser: {} // 当前登录用户信息
			}
		},
		onLoad() {

		},
		onShow() {
			// 从本地存储加载当前用户信息
			const user = uni.getStorageSync('currentUser');
			if (user) {
				this.currentUser = user;
			} else {
				// 如果未登录，跳转到登录页面
				uni.redirectTo({
					url: '/pages/login/login'
				});
			}
		},
		
		methods: {
			message(){
				uni.request({
					url:`http://localhost:3000/users`,
					success:(res)=>{
						 this.users = res.data;      
					}
				})
			},
			// 退出登录
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							// 清除用户信息
							uni.removeStorageSync('currentUser');
							// 跳转到登录页面
							uni.redirectTo({
								url: '/pages/login/login'
							});
						}
					}
				});
			},
			//点击我的地址
			myaddress(){
				uni.navigateTo({
					url: '/pages/own/myaddress'
				});
			},
			//点击我的关注
			mylove(){
				uni.navigateTo({
					url: '/pages/own/mylove'
				});
			},
			//点击我的订单
			myorders(){
				uni.switchTab({
					url: '/pages/orders/index'
				});
			},

		}
	}
</script>

<style  scoped>
    /* 头部 */
	/* .content{
		display: flex;
		flex-direction: column;
		align-items: center;

	} */
	.content .header{
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 230px;
		background-color: rgb(17, 206, 240);

		
	}
	.content .header .headerimg{
		margin-top: 20px;

	}
	.content .header .headerimg img{
		margin-top: 30px;
		border-radius: 50px;
		height:80px;
	    width:80px
	}
	/* 中间 */
	.middle .middlelist{
		padding-top: 20px;
		background-color: antiquewhite;
		height: 400px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

	}
	.middle .middlelist .middleitem{
		width: 90%;
		height: 100px;
		background-color: aliceblue;
		border-radius: 4pt;
		border: 1px solid rgb(221, 216, 216);
		display: flex;
		/* justify-content: center; */
		align-items: center;
		padding-left: 20px;

	}
	/* 退出登录 */
	.middlelogin{
		margin-top: 30px;

	}
</style>
